<!-- TOP START -->
<div class="forms-wrap">
    <!-- 基础信息 START -->
    <h3>基本信息</h3>

    <!-- 入库单号 -->
    <nz-form-item *ngIf="!routeParams.type && routeParams.id > 0">
        <nz-form-label
            nz-col>
            入库单号
        </nz-form-label>
        <nz-form-control
            nz-col
            nzFlex="400px">
            <input type="text" placeholder="入库单号" nz-input [(ngModel)]="formParams.warehousingNumber" [disabled]="true">
        </nz-form-control>
    </nz-form-item>

    <!-- 采购单号 -->
    <nz-form-item>
        <nz-form-label
            nz-col
            nzRequired>
            采购单号
        </nz-form-label>
        <nz-form-control
            nz-col
            nzFlex="400px">
            <nz-select
                nzShowSearch
                nzAllowClear
                nzPlaceHolder="请选择采购单号"
                [disabled]="routeParams.id > 0"
                [(ngModel)]="formParams.warehousing.purchaseNumber"
                (ngModelChange)="purchaseChange($event)">
                <nz-option
                    *ngFor="let item of purchaseLists"
                    [nzLabel]="item.purchaseNumber"
                    [nzValue]="item.purchaseNumber">
                </nz-option>
            </nz-select>
        </nz-form-control>
        <p class="tip-p">重新选择以后，采购内容会被清空，计划单内容会重新加载</p>
    </nz-form-item>

    <!-- 入库仓库 -->
    <nz-form-item>
        <nz-form-label
            nz-col
            nzRequired>
            入库仓库
        </nz-form-label>
        <nz-form-control
            nz-col
            nzFlex="400px">
            <nz-select
                nzShowSearch
                nzAllowClear
                nzPlaceHolder="请选择入库仓库"
                [(ngModel)]="formParams.warehousing.whPutId">
                <nz-option
                    *ngFor="let item of warehouseLists"
                    [nzLabel]="item.name"
                    [nzValue]="item.id">
                </nz-option>
            </nz-select>
        </nz-form-control>
    </nz-form-item >
  
    <!-- 备注 -->
    <nz-form-item>
        <nz-form-label
            nz-col>
            备注
        </nz-form-label>
        <nz-form-control
            nz-col
            nzFlex="400px">
            <nz-textarea-count [nzMaxCharacterCount]="100">
                <textarea
                    class="textarea-cont"
                    nz-input
                    maxlength="100"
                    placeholder="仅内部可见"
                    [(ngModel)]="formParams.warehousing.remark">
                </textarea>
            </nz-textarea-count>
        </nz-form-control>
    </nz-form-item >
    <!-- 基础信息 END -->
  
    <!-- 入库详情 START -->
    <h3 class="title-h">入库详情</h3>

    <div class="table-box">
        <!-- Table -->
        <div class="table-wrap">
            <!-- 申请单table TOP START -->
            <div class="table-item">
                <button nz-button nzType="link" class="all-btn" [disabled]="!purchaseTables.length" (click)="selectAll(0)">全部入库</button>
                <nz-table
                    #topTable
                    [nzLoading]="purchaseTableLoading"
                    [nzData]="purchaseTables"
                    nzBordered
                    nzSize="small"
                    nzTitle="{{ formParams.warehousing.purchaseNumber ? '以下是采购单【' + formParams.warehousing.purchaseNumber + '】的所有内容' : '请选择采购单' }}"
                    [nzShowPagination]="false"
                    [nzScroll]="{ x: '1200px', y: '650px' }"
                    [nzWidthConfig]="nzWidthConfig">
                    <thead>
                        <tr>
                            <th rowspan="2" nzLeft>序号</th>
                            <th colspan="4">商品信息</th>
                            <th colspan="5">采购单信息</th>
                            <th nzAlign="center">本次入库信息</th>
                            <th rowspan="2" nzAlign="center" nzRight>操作</th>
                        </tr>
                        <tr>
                            <th nzAlign="center">商品编号</th>
                            <th nzAlign="center">商品名称</th>
                            <th nzAlign="center">商品69码</th>
                            <th nzAlign="center">标准采购价 (含税)</th>
                            <th nzAlign="center">约定交货日期</th>
                            <th nzAlign="center">采购价(含税)</th>
                            <th nzAlign="center">采购数量</th>
                            <th nzAlign="center">冻结数量</th>
                            <th nzAlign="center">已入库数量</th>
                            <th nzAlign="center">入库数量</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr *ngFor="let data of purchaseTables; let index = index;">
                            <!-- 序号 -->
                            <td nzAlign="center" nzLeft>{{ index + 1 }}</td>
                            <!-- 商品编号 -->
                            <td nzAlign="center">{{ data.id }}</td>
                            <!-- 商品名称 -->
                            <td nzAlign="center" nzBreakWord>{{ data.name || '-' }}</td>
                            <!-- 商品69码 -->
                            <td nzAlign="center">{{ data.code || '-' }}</td>
                            <!-- 标准采购价 (含税) -->
                            <td nzAlign="center">
                                {{ (data.standardCostPrice || data.standardCostPrice != '0') ? '￥' + (data.standardCostPrice | number : '0.4-4') : '-'}}
                            </td>
                            <!-- 约定交货日期 -->
                            <td nzAlign="center">{{ data.deliveryTime | date: 'yyyy-MM-dd' }}</td>
                            <!-- 采购价(含税) -->
                            <td nzAlign="center">
                                {{'￥' + (data.purchasePrice | number : '0.4-4')}}
                            </td>
                            <!-- 采购数量 -->
                            <td nzAlign="center">{{ data.purchaseNumber }}</td>
                            <!-- 冻结数量 -->
                            <td nzAlign="center">{{ data.frozenNumber }}</td>
                            <!-- 已入库数量 -->
                            <td nzAlign="center">{{ data.stockNumber }}</td>
                            <!-- 入库数量 -->
                            <td nzAlign="center">-</td>
                            <!-- 操作 -->
                            <td nzAlign="center" nzRight>
                                <button
                                    nz-button
                                    nz-button-tdlink
                                    nzType="link"
                                    [disabled]="(data.purchaseNumber - data.frozenNumber - data.stockNumber) <= 0 && !backupSelectedTables.includes(data.planId)"
                                    (click)="singleChoice(data, index)">
                                    {{ data.isShow == 0 ? '入库' : '取消入库' }}
                                </button>
                            </td>
                        </tr>

                        <!-- 合计 -->
                        <tr *ngIf="purchaseTables.length" class="tr-bg">
                            <td colSpan="6" nzAlign="center">-</td>
                            <td nzAlign="center">
                                <strong>合计</strong>
                            </td>
                            <td nzAlign="center">{{ getCombinedTotal('purchaseNumber', purchaseTables) }}</td>
                            <td nzAlign="center">{{ getCombinedTotal('frozenNumber', purchaseTables) }}</td>
                            <td nzAlign="center">{{ getCombinedTotal('stockNumber', purchaseTables) }}</td>
                            <td nzAlign="center">-</td>
                            <td nzAlign="center">-</td>
                        </tr>
                    </tbody>
                </nz-table>
            </div>
            <!-- 申请单table TOP END -->

            <!-- 入库内容 BOM START -->
            <div *ngIf="selectedTables.length > 0" class="table-item">
                <button nz-button nzType="link" class="all-btn" [disabled]="!selectedTables.length" (click)="selectAll(1)">清空已选</button>
                <nz-table
                    #topTable
                    [nzData]="selectedTables"
                    nzBordered
                    nzSize="small"
                    nzTitle="以下是本次要采购的内容"
                    [nzShowPagination]="false"
                    [nzScroll]="{ x: '1200px', y: '650px' }"
                    [nzWidthConfig]="nzWidthConfig">
                    <thead>
                        <tr>
                            <th rowspan="2" nzLeft>序号</th>
                            <th colspan="4">商品信息</th>
                            <th colspan="5">采购单信息</th>
                            <th nzAlign="center">本次入库信息</th>
                            <th rowspan="2" nzAlign="center" nzRight>操作</th>
                        </tr>
                        <tr>
                            <th nzAlign="center">商品编号</th>
                            <th nzAlign="center">商品名称</th>
                            <th nzAlign="center">商品69码</th>
                            <th nzAlign="center">标准采购价 (含税)</th>
                            <th nzAlign="center">约定交货日期</th>
                            <th nzAlign="center">采购价(含税)</th>
                            <th nzAlign="center">采购数量</th>
                            <th nzAlign="center">冻结数量</th>
                            <th nzAlign="center">已入库数量</th>
                            <th nzAlign="center">入库数量</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr *ngFor="let data of selectedTables; let index = index;">
                            <!-- 序号 -->
                            <td nzAlign="center" nzLeft>{{ index + 1 }}</td>
                            <!-- 商品编号 -->
                            <td nzAlign="center">{{ data.planDetailsId }}</td>
                            <!-- 商品名称 -->
                            <td nzAlign="center" nzBreakWord>{{ data.name || '-' }}</td>
                            <!-- 商品69码 -->
                            <td nzAlign="center">{{ data.code || '-' }}</td>
                            <!-- 标准采购价 (含税) -->
                            <td nzAlign="center">
                                {{ (data.standardCostPrice || data.standardCostPrice != '0') ? '￥' + (data.standardCostPrice | number : '0.4-4') : '-'}}
                            </td>
                            <!-- 约定交货日期 -->
                            <td nzAlign="center">{{ data.deliveryTime | date: 'yyyy-MM-dd' }}</td>
                            <!-- 采购价(含税) -->
                            <td nzAlign="center">
                                {{'￥' + (data.purchasePrice | number : '0.4-4')}}
                            </td>
                            <!-- 采购数量 -->
                            <td nzAlign="center">{{ data.purchaseNumber }}</td>
                            <!-- 冻结数量 -->
                            <td nzAlign="center">{{ data.frozenNumber }}</td>
                            <!-- 已入库数量 -->
                            <td nzAlign="center">{{ data.stockNumber }}</td>
                            <!-- 入库数量 -->
                            <td nzAlign="center">
                                <nz-input-number
                                    [nzId]="'putSaveInputID' + index"
                                    [(ngModel)]="data.number"
                                    [nzMin]="1"
                                    [nzMax]="data.maxStockNumber"
                                    (keydown)="onKeydownEnter($event, index)">
                                </nz-input-number>
                            </td>
                            <!-- 操作 -->
                            <td nzAlign="center" nzRight>
                                <button
                                    nz-button
                                    nz-button-tdlink
                                    nzType="link"
                                    (click)="singleChoice(data, index)">
                                    取消入库
                                </button>
                            </td>
                        </tr>

                        <!-- 合计 -->
                        <tr class="tr-bg">
                            <td colSpan="6" nzAlign="center">-</td>
                            <td nzAlign="center">
                                <strong>合计</strong>
                            </td>
                            <td nzAlign="center">{{ getCombinedTotal('purchaseNumber', selectedTables) }}</td>
                            <td nzAlign="center">{{ getCombinedTotal('frozenNumber', selectedTables) }}</td>
                            <td nzAlign="center">{{ getCombinedTotal('stockNumber', selectedTables) }}</td>
                            <td nzAlign="center">{{ getCombinedTotal('number', selectedTables) }}</td>
                            <td nzAlign="center">-</td>
                        </tr>
                    </tbody>
                </nz-table>
            </div>
            <!-- 入库内容 BOM END -->
        </div>
    </div>
    <!-- 入库详情 END -->
  
    <!-- footer -->
    <div class="footer-wrap">
        <nz-divider></nz-divider>
        <div class="foot-btns">
            <app-bt-group
                btType="dashed"
                btText="保存"
                [isLoading]="subLoading"
                (btClick)="preserData()">
            </app-bt-group>
  
            <app-bt-group
                btType="default"
                btText="返回">
            </app-bt-group>
        </div>
    </div>
</div>
<!-- TOP END -->